package day021.tcp.demo2;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TcpClient {
    private static final Logger LOGGER = LoggerFactory.getLogger("TcpClient类");

    public static void main(String[] args) throws IOException {
        Socket client = new Socket("127.0.0.1", 9090);

        OutputStream netOutput = client.getOutputStream();
        netOutput.write("你好".getBytes());

        InputStream netInput = client.getInputStream();
        byte[] buf = new byte[1024];
        int len = netInput.read(buf);
        String msg = new String(buf, 0, len);
        LOGGER.trace("服务器回馈的数据：" + msg);

        netInput.close();
        netOutput.close();
        client.close();
    }
}
